* ======================================
* ----------- Distance plots -----------
* ======================================

	
	use $dta\EstimationSample.dta, clear

	
* Import variables
* ================
	
	rename Voter_id idPers
	
	* Income
	merge 1:1 idPers year using $dta/ImportIncome.dta, keep(master matched) nogen

	* Import educ
	merge 1:1 idPers year using $dta/ImportEduc.dta, keep(master matched) nogen
	
	* Import marriage
	merge 1:1 idPers year using $dta/ImportMarriage.dta, keep(master matched) nogen
	
	* Import donation
	merge 1:1 idPers year using $dta/ImportDonations.dta, keep(master matched) nogen
	replace donation = 0 if donation == .

	rename idPers Voter_id
	
	
* Income	
* ======
	
	* Fam1
	preserve
	keep if Fam1 == 1
	drop if Fam1Any == 1 & Fam1Pol_dist == . // Missing distance
	run $prog\prog_distplot "Fam1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5 4 2 4 2 "Fam1Dist" ///
		"Panel A: Family" incomeUSD
	restore

	* Work1
	preserve
	keep if Work1 == 1
	drop if Work1Any == 1 & Work1Pol_dist == . // Missing distance
	run $prog\prog_distplot "Work1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5 6 3 6 3 "Work1Dist" ///
		"Panel B: Co-workers" incomeUSD
	restore

	* Imm1
	preserve
	keep if Imm1 == 1
	drop if Imm1Any == 1 & Imm1Pol_dist == . // Missing distance
	do $prog\prog_distplot "Imm1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5 4 2 8 4 "Imm1Dist" ///
		"Panel C: Immigrants" incomeUSD
	restore

	graph combine Fam1Dist Work1Dist Imm1Dist, ysize(8) col(1) scheme(plotplain)
	graph export "$figs\DistplotsBalance_income.pdf",replace

	
* Education	
* =========	
	
	* Fam1
	preserve
	keep if Fam1 == 1
	drop if Fam1Any == 1 & Fam1Pol_dist == . // Missing distance
	run $prog\prog_distplot "Fam1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5 0.02 0.01 0.02 0.01 "Fam1Dist" ///
		"Panel A: Family" hieduc
	restore

	* Work1
	preserve
	keep if Work1 == 1
	drop if Work1Any == 1 & Work1Pol_dist == . // Missing distance
	run $prog\prog_distplot "Work1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5 0.02 0.01 0.04 0.02 "Work1Dist" ///
		"Panel B: Co-workers" hieduc
	restore

	* Imm1
	preserve
	keep if Imm1 == 1
	drop if Imm1Any == 1 & Imm1Pol_dist == . // Missing distance
	do $prog\prog_distplot "Imm1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5 0.02 0.01 0.04 0.02 "Imm1Dist" ///
		"Panel C: Immigrants" hieduc
	restore

	graph combine Fam1Dist Work1Dist Imm1Dist, ysize(8) col(1) scheme(plotplain)
	graph export "$figs\DistplotsBalance_education.pdf",replace
	

* Donations
* =========	
	
	* Fam1
	preserve
	keep if Fam1 == 1
	drop if Fam1Any == 1 & Fam1Pol_dist == . // Missing distance
	run $prog\prog_distplot "Fam1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5 0.06 0.03 0.06 0.03 "Fam1Dist" ///
		"Panel A: Family" donation
	restore

	* Work1
	preserve
	keep if Work1 == 1
	drop if Work1Any == 1 & Work1Pol_dist == . // Missing distance
	run $prog\prog_distplot "Work1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5 0.04 0.02 0.04 0.02 "Work1Dist" ///
		"Panel B: Co-workers" donation
	restore

	* Imm1
	preserve
	keep if Imm1 == 1
	drop if Imm1Any == 1 & Imm1Pol_dist == . // Missing distance
	do $prog\prog_distplot "Imm1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5 0.06 0.03 0.16 0.08 "Imm1Dist" ///
		"Panel C: Immigrants" donation
	restore

	graph combine Fam1Dist Work1Dist Imm1Dist, ysize(8) col(1) scheme(plotplain)
	graph export "$figs\DistplotsBalance_donations.pdf",replace
	
	
	
* Married	
* =======
	
	* Fam1
	preserve
	keep if Fam1 == 1
	drop if Fam1Any == 1 & Fam1Pol_dist == . // Missing distance
	run $prog\prog_distplot "Fam1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5 0.04 0.02 0.04 0.02 "Fam1Dist" ///
		"Panel A: Family" married
	restore

	* Work1
	preserve
	keep if Work1 == 1
	drop if Work1Any == 1 & Work1Pol_dist == . // Missing distance
	run $prog\prog_distplot "Work1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5 0.04 0.02 0.04 0.02 "Work1Dist" ///
		"Panel B: Co-workers" married
	restore

	* Imm1
	preserve
	keep if Imm1 == 1
	drop if Imm1Any == 1 & Imm1Pol_dist == . // Missing distance
	do $prog\prog_distplot "Imm1" 9 3 10 200 10 "small" "vsmall" "medsmall" ///
		"vsmall" "medium" "medium" 5.5  0.04 0.02 0.12 0.06 "Imm1Dist" ///
		"Panel C: Immigrants" married
	restore

	graph combine Fam1Dist Work1Dist Imm1Dist, ysize(8) col(1) scheme(plotplain)
	graph export "$figs\DistplotsBalance_married.pdf",replace
